package com.tuozixuan.service.impl;

import java.util.Date;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.tuozixuan.model.User;
import com.tuozixuan.service.UserService;

@Service
public class UserServiceImpl implements UserService {

	@Override
	@Cacheable(value = "getUserInfo")
	public User getUser() {
		System.out.println("從數據庫中獲取user信息。。。");
		User user = new User();
		user.setId(1L);
		user.setName("tuozixuan");
		user.setAge(18);
		user.setCreateDate(new Date());
		return user;
	}

	@Override
	@Cacheable(value = "getUserCount")
	public int getUserCount() {
		System.out.println("query from db");
		return 8;
	}

	@Override
	@Cacheable(value = "getUserById", key="#id")
	public User getUserById(Long id) {
		System.out.println("===query from db===");
		User user = new User();
		user.setId(id);
		user.setName("tuozixuan" + id);
		user.setAge(18);
		user.setCreateDate(new Date());
		return user;
	}
	
	@Override
	@Cacheable(value = "getUserByName")
	public User getUserByName(String name) {
		System.out.println("===query from db===");
		User user = new User();
		user.setId(1L);
		user.setName(name);
		user.setAge(18);
		user.setCreateDate(new Date());
		return user;
	}

}
